package edu.bu.cs673b1s1p3.nextbus.main;

import java.util.ArrayList;
import java.util.List;

import edu.bu.cs673b1s1p3.nextbus.service.routeconfig.Stop;

public class StopsToArray {
	
	private final static int SELECT_ROUTE_COLS = 5;
	private final static int SEARCH_ADDRESS_COLS = 6;
	
	/**
	 *  Converts List of Stop objects into 2D Array for placement into JTable
	 * 
	 * @param list List of Stop Objects
	 * @return String[][] stopListArray
	 */
	public static String[][] convert(List<Stop> list) 
	{
		String[][] stopListArray = new String[list.size()][SELECT_ROUTE_COLS];
		int i = 0;
		
		
		for(Stop stop: list)
		{
			
			//First Column: Stop Letter Indicator
			stopListArray[i][0] = Integer.toString(i+1);
			
			//Second Column: Stop Title
			stopListArray[i][1] = stop.getTitle();
			
			//TODO - Third Column: Next Bus Time
			stopListArray[i][2] = stop.getNextBusTime();
			
			//Fourth Column: Latitude (Hidden)
			stopListArray[i][3] = stop.getLat().toString();
			
			//Fifth Column: Longitude (Hidden)
			stopListArray[i][4] = stop.getLon().toString();
			
			i++;
		}
		return stopListArray;
	}
	
	/**
	 *  Converts ArrayList of RouteStopGeoPositionDTO objects into 2D Array for placement into JTable
	 * 
	 * @param closestStops List of RouteStopGeoPositionDTO Objects
	 * @return String[][] stopListArray
	 */
	public static String[][] convert(ArrayList<RouteStopGeoPositionDTO> closestStops) 
	{
		String[][] stopListArray = new String[closestStops.size()][SEARCH_ADDRESS_COLS];
		int i = 0;
		
		for (RouteStopGeoPositionDTO r : closestStops) {
			//First Column: Stop Letter Indicator
			stopListArray[i][0] = Integer.toString(i+1);
			
			//Second Column: Route Tag
			stopListArray[i][1] = r.getRouteTag();
			
			//Third Column: Stop Title
			stopListArray[i][2] = r.getStop().getTitle();
			
			//Fourth Column: NextBus Time
			stopListArray[i][3] = r.getNextBusTime();
			
			//Fifth Column: Latitude (Hidden)
			stopListArray[i][4] = r.getStop().getLat().toString();
			
			//Sixth Column: Longitude (Hidden)
			stopListArray[i][5] = r.getStop().getLon().toString();
			
			i++;
		}
		return stopListArray;
	}
}
